// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PROVIDER_CONTACT_CCQ_I19 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 PRD",6)]
  	    [HL7Field(HL7Version.v27, 6, HL7Repeat.False, HL7Required.True,"PRD")]
	    public PRD PRD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("7 CTD",7)]
  	    [HL7Field(HL7Version.v27, 7, HL7Repeat.True, HL7Required.False,"CTD")]
	    public CTD[] CTD {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PRD = PopSegmentParseAndCheckRequired<PRD>(availableData, options, "PRD");
			CTD = PopSegmentParseAndCheckRequiredArray<CTD>(availableData, options, "CTD");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPRD = availableData.StartsWith("PRD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRD", options.Version) || isPRD) {
				return isPRD;
			}
			bool isCTD = availableData.StartsWith("CTD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CTD", options.Version) || isCTD) {
				return isCTD;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PROVIDER_CONTACT";
			}
        }

        static PROVIDER_CONTACT_CCQ_I19() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PROVIDER_CONTACT_CCQ_I19));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PRD != null) {
			string segmentValue = PRD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CTD != null && CTD.Length > 0) {
			for (int i = 0; i < CTD.Length; i++) {
				string segmentValue = CTD[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

